package leetcode.p169;

/***
 * Majority Element
 * 找数组中超过一半个数的数字
 */
public class Solution {

    public int majorityElement(int[] nums) {
        int res = nums[0];
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            if(count == 0) {
                res = nums[i];
                ++count;
            }else if(res == nums[i]) {
                ++count;
            }else {
                --count;
            }
        }
        return res;
    }
}
